/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						 strip_resource_name.h

	$Header: /resource_editor/strip_resource_name.h $

	$NoKeywords: $

 ************************************************************************/

// kill the 255+ character identifier warning.  Templates tend to exceed that easily.
#include "precompiled.h"
#pragma warning( disable: 4786 )


#include "strip_resource_name.h"

// functions to manipulate strings with this format:
// type_name.folder_name.resource_name.h4d
// folder_name can be repeated 0-infinite times

std::string strip_extension( std::string name )
{
	std::string::size_type position = name.rfind('.');

	if (position != std::string::npos)
		name.erase( position );
	return name;
}

std::string strip_prefix( std::string name )
{
	std::string::size_type position = name.find( '.' );

	if (position != std::string::npos)
		name.erase( 0, position + 1 );
	return name;
}

std::string strip_type_and_extension( std::string name )
{
	std::string::size_type position = name.rfind('.');

	if (position != std::string::npos)
		name.erase( position );
	position = name.find( '.' );
	if (position != std::string::npos)
		name.erase( 0, position + 1 );
	return name;
}

std::string strip_folder( std::string name )
{
	std::string::size_type position;

	position = name.rfind( '.' );
	if (position != std::string::npos)
		name.erase( 0, position + 1 );
	return name;
}


std::string strip_folder_and_extension( std::string name )
{
	std::string::size_type position = name.rfind('.');

	if (position != std::string::npos)
		name.erase( position );
	position = name.rfind( '.' );
	if (position != std::string::npos)
		name.erase( 0, position + 1 );
	return name;
}

std::string get_folder_name( std::string name )
{
	std::string::size_type position = name.rfind('.');

	if (position != std::string::npos)
		name.erase( position );
	position = name.find( '.' );
	if (position != std::string::npos)
		name.erase( 0, position + 1 );
	position = name.rfind( '.' );
	if (position == std::string::npos)
		name.erase();
	else
		name.erase( position );
	if (!name.empty())
		name += '.';
	return name;
}

std::string get_prefix( std::string name )
{
	std::string::size_type position = name.find( '.' );

	if ( position == std::string::npos )
		position = 0;
	name.erase( position );

	return name;
}

std::string get_extension( std::string name )
{
	std::string::size_type position = name.rfind( '.' );

	if ( position != std::string::npos )
		++position;
	name.erase( 0, position );

	return name;
}
